package com.qys.livesMall.navy.controller.sys;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qys.livesMall.common.exception.QysException;
import com.qys.livesMall.common.result.R;
import com.qys.livesMall.navy.enums.NavyMessageEnum;
import com.qys.livesMall.navy.model.dto.NavyLanguageManageDto;
import com.qys.livesMall.navy.model.dto.NavyLanguageManageQueryPackageDto;
import com.qys.livesMall.navy.model.vo.NavyLanguageManageVo;
import com.qys.livesMall.navy.service.H2NavyLanguageManageService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 水军语言管理 前端控制器
 * </p>
 *
 * @author wzy
 * @since 2023-07-04
 */
@Tag(name = "水军语言管理", description = "水军语言管理")
@RestController
@RequestMapping("/navy/navyLanguageManage")
public class H2NavyLanguageManageController {
    @Resource
    private H2NavyLanguageManageService languageManageService;

    @Operation(summary = "添加水军语言管理")
    @PostMapping("/add")
    public R add(@RequestBody @Validated NavyLanguageManageDto navyLanguageManageDto){
        return languageManageService.add(navyLanguageManageDto)? R.ok():R.fail();
    }

    @Operation(summary = "修改水军语言管理")
    @PostMapping("/update")
    public R update(@RequestBody @Validated NavyLanguageManageDto navyLanguageManageDto){
        if (null == navyLanguageManageDto.getId()){
            throw new QysException(NavyMessageEnum.NAVY_NOT_ID);
        }
        return languageManageService.update(navyLanguageManageDto)? R.ok():R.fail();
    }

    @Operation(summary = "删除水军语言管理")
    @DeleteMapping(value = "/delete/{id}")
    public R delete(@PathVariable Long id){
        languageManageService.removeById(id);
        return R.ok();
    }

    @Operation(summary = "查询水军语言管理")
    @PostMapping("query")
    public R<IPage<NavyLanguageManageVo>> query(@RequestBody @Validated NavyLanguageManageQueryPackageDto navyLanguageManageQueryPackageDto){
       return R.ok(languageManageService.query(navyLanguageManageQueryPackageDto));
    }

    @Operation(summary = "查询水军语言管理详情")
    @GetMapping(value = "/info/{id}")
    public R<NavyLanguageManageVo> info(@PathVariable Long id){
        return R.ok(languageManageService.info(id));
    }
}
